import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

import rmi.RMIInterface;

public class RMIServer  extends UnicastRemoteObject implements RMIInterface {

	private PrintWriter out;

	/**
	 * constructor
	 * 
	 * @param file
	 *            the path of file where append result
	 * @throws IOException
	 *             if an error occurred
	 */
	public RMIServer(String file) throws IOException {
		out = new PrintWriter(new FileWriter(file, true));
	}

	/**
	 * append result to the file and print it. this method is synchronized
	 * because more client may send result in the same moment
	 * 
	 * @param results
	 *            the result string
	 * @thrown RemoteException
	 */
	@Override
	public synchronized void sendResult(String results) throws RemoteException {
		System.out.println("Scrivo su File");
		System.out.println(results);
		out.println(results);
		out.flush();
	}
}